package com.hjl.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ServivE
 * @version 0.1
 * @className AServlet
 * @description
 * @date 2024/7/25 17:51
 * @since jdk11
 * <p>
 * 转发与重定向
 */
@WebServlet(value = "/a")
public class AServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //转发
        //request作用域存储数据
        request.setAttribute("key","你好啊，servlet");
        //转发给另一个servlet
        request.getRequestDispatcher("/b").forward(request,response);
        //重定向
        response.sendRedirect("/b");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
